<template>
  <div class="login">
    <h2>登录</h2>
    <input v-model="username" placeholder="请输入用户名" />
    <button @click="login">登录</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: ''
    };
  },
  methods: {
    login() {
      this.$store.commit('setUser', { username: this.username, role: this.username === 'admin' ? 'admin' : 'student' });
      this.$router.push('/');
    }
  }
};
</script>